/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package manager;

import entity.ConnectDB;
import entity.Film;
import entity.Films;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import marshall.GenXML;

/**
 *
 * @author tiz
 */
public class FilmsManager {

    public FilmsManager() {
    }

    public Films getFilmsDB() {
        try {
            Films fList = new Films();
            Film film = null;
            ConnectDB con = new ConnectDB();
            Connection connection = con.getCon();
            Statement stm = connection.createStatement();

//            String query = "SELECT * FROM Films WHERE Name like '%" + filmName + "%'";
            String query = "SELECT * FROM Films";
            ResultSet rs = stm.executeQuery(query);
            while (rs.next()) {
                String id = rs.getString(1);
                String name = rs.getString(2);
                BigDecimal budget = rs.getBigDecimal(3);
                String date = rs.getString(4);
                String director = rs.getString(5);
                String descript = rs.getString(6);
                String url = rs.getString(7);
                film = new Film(id, name, budget, date, director, descript, url);
                fList.setFilm(film);
            }
            return fList;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public void filmsToXML(String filename) {
        FilmsManager fm = new FilmsManager();
        Films filmList = new Films();
        filmList = fm.getFilmsDB();

        GenXML genxml = new GenXML();
        genxml.mar(filmList, filename);
    }

    public void addNewFilm(){
        
    }
}
